{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <select name="status">
                                <option value="">审核状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待审核</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>通过</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>驳回</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="isshow">
                                <option value="">是否显示</option>
                                <option value="1" {if !empty(input('get.isshow')) &&
                                    input('get.isshow')==1}selected{/if}>是</option>
                                <option value="2" {if !empty(input('get.isshow')) &&
                                    input('get.isshow')==2}selected{/if}>否</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="type">
                                <option value="">分类类型</option>
                                {foreach $class as $v}
                                <option value="{$v.id}" {if !empty(input('get.type')) &&
                                    input('get.type')==$v.id}selected{/if}>{$v.name}</option>
                                {/foreach}

                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="province" data-area="" lay-filter="province">
                                <option value="">选择省</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="city" data-area="" lay-filter="city">
                                <option value="">选择市</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="area" data-area="" lay-filter="area">
                                <option value="">选择区</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="street" data-area="" lay-filter="street">
                                <option value="">选择街道</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="title" placeholder="信息标题|联系人电话" value="{:input('get.title')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">搜索</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="data_edit('添加','second_add')"><i
                            class="layui-icon">&#xe654;</i>添加</button>&nbsp;
                    共有数据：<strong id="count">{$list->total()}</strong> 条
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>发布用户</th>
                                <th>封面</th>
                                <th>类型</th>
                                <th>售价</th>
                                <th>省市区</th>
                                <th>定位地址</th>
                                <th>联系电话</th>
                                <th>是否推荐</th>
                                <th>上下架</th>
                                <th>创建时间</th>
                                <th>审核状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td>{$v.id|default='0'}</td>
                                <td>{$v.title|default=''}</td>
                                <td>{$v.name|default=''}</td>
                                <td><img src="{$v.images.0|default=''}" {if
                                        !empty($v.images.0)}onclick="showimg('{$v.images.0}')" {/if} />
                                </td>
                                <td>{$v.type_name|default=''}</td>
                                <td>{$v.price|default='0'}</td>
                                <td>{$v.province_name|default=''}{$v.city_name|default=''}{$v.area_name|default=''}</td>
                                <td>{$v.posaddress|default=''}</td>
                                <td>{$v.phone|default='0'}</td>
                                <td>
                                    {switch $v.ishot }
                                    {case 1 } <button type="button" class="layui-btn layui-bg-red">默认</button>
                                    {/case}
                                    {case 2}<button type="button" class="layui-btn layui-bg-blue">推荐</button>{/case}
                                    {default /}无
                                    {/switch}
                                </td>
                                <td>
                                    {switch $v.isshow }
                                    {case 1 } <button type="button" class="layui-btn layui-bg-blue">上级</button>
                                    {/case}
                                    {case 2}<button type="button" class="layui-btn layui-bg-red">下架</button>{/case}
                                    {default /}无
                                    {/switch}
                                </td>
                                <td>{$v.created|default=''}</td>
                                <td>
                                    {switch $v.status }
                                    {case 1 } <button type="button" class="layui-btn layui-bg-red">待审核</button>
                                    {/case}
                                    {case 2}<button type="button" class="layui-btn layui-bg-blue">通过</button>{/case}
                                    {case 3}<button type="button" class="layui-btn layui-bg-gray">驳回</button>{/case}
                                    {default /}无
                                    {/switch}
                                </td>
                                <td class="td-manage">
                                    <a title="编辑" onclick="data_edit('编辑','/circle/second_add?id={$v.id}')"
                                        href="javascript:;" class="layui-btn">
                                        编辑
                                    </a>
                                    <a title="删除" onclick="data_del(this,'/circle/second_del','{$v.id}')"
                                        href="javascript:;" class="layui-btn-danger layui-btn">
                                        删除
                                    </a>
                                </td>

                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload;
        //渲染省份
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 1 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择省份</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type != 1) {
                            if (obj.area_code == res.province) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.province) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="province"]').html(str);
                    form.render();
                }
            }
        });
        //选软城市
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 2 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择城市</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type != 1) {
                            if (obj.area_code == res.city) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.city) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="city"]').html(str);
                    form.render();
                }
            }
        });
        //选软区域
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 3 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择区域</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.area_code;
                        if (res.type == 3) {
                            if (obj.area_code == res.area && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.area_code == res.area && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="area"]').html(str);
                    form.render();
                }
            }
        });
        //选软街道
        $.ajax({
            type: 'get',
            url: '/base/getarea',
            data: { level: 4 },
            success: function (res) {
                if (res.code == 0) {
                    var str = '<option value="">请选择街道|村镇</option>';
                    $.each(res.data, function (i, obj) {
                        str += '<option value="' + obj.id;
                        if (res.type == 4) {
                            if (obj.id == res.street && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '" disabled>' + obj.name;
                            }
                        } else {
                            if (obj.id == res.street && "{$data['id']|default='0'}" > 0) {
                                str += '" selected>' + obj.name;
                            } else {
                                str += '">' + obj.name;
                            }
                        }
                        str += '</option>';
                    });
                    $('select[name="street"]').html(str);
                    form.render();
                }
            }
        });
        //监听省份选择市区
        form.on('select(province)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 2 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择城市</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="city"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });

        form.on('select(city)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 3 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择区域</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="area"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
        form.on('select(area)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 4 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择街道|村镇</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.id;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="street"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
        //图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: 'users_top'
            , accept: 'file'
            , exts: 'xls|csv'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.status > 0) {
                    return layer.msg(res.msg);
                }
                //上传成功
                return layer.msg(res.msg);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
    function showimg(imgs) {
        console.log(imgs);
        layer.open({
            type: 1,
            title: false,
            shadeClose: true,
            skin: 'layui-layer-nobg', //没有背景色
            content: "<img src='" + imgs + "' style='width:100%;height: 100%;'>"
        });
    }
    function orderstr(title, url, id, status) {
        layer.confirm(title, { title: '请谨慎操作' }, function (index) {
            $.post(url, { id: id, status: status }, function (data) {
                if (data.code == 0) {
                    layer.msg(data.msg, { icon: 1, time: 1000 });
                    location.replace(location.href);
                } else {
                    layer.msg(data.msg, { icon: 2, time: 1000 });
                }
            });
        });
    }
</script>
{include file="public/footer"}